package cj.web.yc.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cj.web.uc.dao.ConfigInfoDAO;
import cj.web.uc.dao.MemberDAO;
import cj.web.yc.dao.VideoOrderDAO;

@Service
public class VideoOrderService {

	private static final String POINT_CODE="RMB_POINT";

	@Autowired
    private VideoOrderDAO videoOrderDAO;
	@Autowired
    private ConfigInfoDAO configInfoDAO;
	@Autowired
    private MemberDAO memberDAO;
	
    public List<Map> queryByOrderNo(String orderNo){
    	return videoOrderDAO.queryByOrderNo(orderNo);
    }
	
    public List<Map> queryById(int id){
    	return videoOrderDAO.queryById(id);
    }
    
    /**
     * 更新订单状态，并且充值用户积分
     * @param memberId	用户ID
     * @param price		价格
     * @param status	状态
     * @param orderNo	订单
     * @param payOrder	付款编号
     * @param payWay	付款方式
     */
    public void updateStatusByNO(int memberId,int price,int status,String orderNo,String payOrder,int payWay){
    	int pointValue = 10;//基数
    	int point = 0;//充值积分
    	List<Map> replis = configInfoDAO.queryByCode(POINT_CODE);
    	if(replis!=null && replis.size()>0){
    		pointValue = Integer.parseInt(replis.get(0).get("value").toString());
    	}
    	point = pointValue*price;//基数*充值积分
    	videoOrderDAO.updateStatusByNO(status, orderNo, payOrder, payWay);
    	memberDAO.updateMemberPoint(memberId, point);
    }
    
    public void deleteById(int id){
    	videoOrderDAO.deleteById(id);
    }
	
    public int create(int id,String orderNo,int memberId,String price,int status,String createUser,String updateUser){
    	return videoOrderDAO.create(id, orderNo, memberId, price, status, createUser, updateUser);
    }
}